package patrol.mobile.com.mobilepatrol.activity.monitor;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;
import com.dl7.recycler.listener.OnRecyclerViewItemClickListener;
import com.google.gson.Gson;

import java.util.HashMap;

import butterknife.BindView;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.CommonListActivity;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.JiankkElefailrptList;
import patrol.mobile.com.mobilepatrol.manager.UserManager;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

/**
 * Created by z on 2018/9/20.
 * Des: 故障报修
 */

public class GzbxActivity extends CommonListActivity {
    @BindView(R.id.titleAddIcon)
    public ImageView titleAddIcon;
    private JiankkElefailrptList jiankkElefailrptList;

    @Override
    protected BaseQuickAdapter initAdapter() {
        return new
                MyBaseQuickAdapter(this);
    }

    @Override
    protected String initTitleName() {
        return "故障报修";
    }

    @Override
    public void initData() {
        super.initData();
        iv_right_title.setImageResource(R.mipmap.add_white);
        iv_right_title.setVisibility(View.VISIBLE);
        mAdapter.setOnItemClickListener(new OnRecyclerViewItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                startActivity(new Intent(view.getContext(), GzbsbActivity.class)
                        .putExtra("data", jiankkElefailrptList.getList().get(position).getId())
                );
            }
        });
        iv_right_title.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(view.getContext(), GzbsbActivity.class));
            }
        });
        getHttpData();
    }


    private void getHttpData() {
        HashMap<String, String> hashMap = new HashMap();
        hashMap.put("orgId", UserManager.getOrgNo());
        HttpSender sender = new HttpSender(this, baseUrl, Urls.getJiankkElefailrptList);
        sender.requestPost(hashMap, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                jiankkElefailrptList = new Gson().fromJson(response, JiankkElefailrptList.class);
                mAdapter.updateItems(jiankkElefailrptList.getList());
            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mAdapter != null) {
            getHttpData();
        }
    }

    public class MyBaseQuickAdapter extends BaseQuickAdapter<JiankkElefailrptList.ListBean> {

        public MyBaseQuickAdapter(Context context) {
            super(context);
        }

        @Override
        protected int attachLayoutRes() {
            return R.layout.item_jdxf_layout;
        }

        @Override
        protected void convert(BaseViewHolder holder, JiankkElefailrptList.ListBean item) {
            holder.setText(R.id.tv_num, (holder.getAdapterPosition() + 1) + "");
            holder.setText(R.id.itemSfzName, item.getOrg().getOrgName());
            holder.setText(R.id.itemSfzXfType, item.getEquipmentName());
            holder.setText(R.id.itemSfzXfJinDu, item.getAuditName());
//            holder.setText(R.id.itemSfzUserName, item.getAccount().getName());
            holder.setText(R.id.itemSfzWfTime, item.getDate());
            holder.getView(R.id.itemSfzUserName).setVisibility(View.GONE);

        }
    }
}
